# -*- coding: utf-8 -*-
# @Time : 2024/4/27 1:14 PM 
# @Author : Wayne
# @Email : 1
# @File : aes_decrypt.py
# @Project : young_python_demo
# @DESCRIPTION :

# -*- coding: utf-8 -*-
# @Time : 2024/2/20 10:13 AM
# @Author : Wayne
# @Email : 1
# @File : no_save.py
# @Project : young_python_demo
# @DESCRIPTION :


from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
import base64

SECRET_KEY = b'sxz4567890123sxz'  # 确保这是16字节长的密钥
ALGORITHM = 'AES'


def decrypt(encrypted_data):
    backend = default_backend()
    cipher = Cipher(algorithms.AES(SECRET_KEY), modes.ECB(), backend=backend)
    decryptor = cipher.decryptor()

    # Base64解码加密数据
    encrypted_bytes = base64.b64decode(encrypted_data)

    # 执行解密
    decrypted_bytes = decryptor.update(encrypted_bytes) + decryptor.finalize()

    return decrypted_bytes.decode('utf-8')


# 使用示例
try:
    encrypted_data = "BfCbPFy6jmA07OAbgD8K+RhS/nMNbN3nmQfhWAOKhWA="
    decrypted_text = decrypt(encrypted_data)
    print(f"Decrypted text: {decrypted_text}")
except Exception as e:
    print(f"An error occurred during decryption: {e}")